<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateTables extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('members', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->char('openid', '28')
                ->unique('openid')
                ->comment('开放平台ID');
            $table->string('nickname', 50)
                ->default('')
                ->comment('昵称');
            $table->string('avatar', 255)
                ->default('')
                ->comment('头像');
            $table->char('phone', 11)
                ->default('')
                ->comment('手机号');
            $table->datetimes();
            $table->comment('用户表');
        });

        Schema::create('lessees', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('member_id')
                ->index('member_id')
                ->comment('用户ID');
            $table->string('name', 10)
                ->comment('姓名');
            $table->char('phone', 11)
                ->comment('手机号');
            $table->char('id_card', 18)
                ->comment('身份证号');
            $table->unsignedTinyInteger('is_default')
                ->default(0)
                ->comment('是否默认:0=否,1=是');
            $table->datetimes();
            $table->comment('承租人表');
        });

        Schema::create('car_categories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 10)
                ->comment('名称');
            $table->string('icon', 255)
                ->default('')
                ->comment('ICON');
            $table->unsignedSmallInteger('weight')
                ->default(0)
                ->comment('权重(越大越靠前)');
            $table->datetimes();
            $table->comment('车辆分类表');
        });

        Schema::create('cars', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->json('car_category_ids')
                ->comment('车辆分类ID');
            $table->json('banner')
                ->comment('轮播图');
            $table->string('cover', 255)
                ->comment('封面图');
            $table->string('name', 10)
                ->comment('名称');
            $table->unsignedSmallInteger('price')
                ->comment('单价(天)');
            $table->string('describe', 32)
                ->comment('描述');
            $table->json('base_config')
                ->comment('基础配置');
            $table->json('high_light_config')
                ->comment('突出配置');
            $table->unsignedInteger('volume')
                ->default(0)
                ->comment('下单量');
            $table->datetimes();
            $table->comment('车辆表');
        });

        Schema::create('insurances', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedTinyInteger('level')
                ->comment('保险等级');
            $table->string('name', 10)
                ->comment('名称');
            $table->string('car_damage', 10)
                ->comment('车损保障');
            $table->string('car_damage_sub', 10)
                ->comment('车损保障副描述');
            $table->string('tripartite', 10)
                ->comment('三者保障');
            $table->string('passenger', 10)
                ->comment('乘客保障');
            $table->unsignedTinyInteger('free_depreciation')
                ->comment('免折旧费:0=否,1=是');
            $table->unsignedTinyInteger('no_need_advance')
                ->comment('无需垫付:0=否,1=是');
            $table->unsignedTinyInteger('free_outage')
                ->comment('免停运费:0=否,1=是');
            $table->unsignedSmallInteger('original_price')
                ->comment('原本单价(天)');
            $table->unsignedSmallInteger('price')
                ->comment('单价(天)');
            $table->text('detail')
                ->comment('详情');
            $table->datetimes();
            $table->comment('保险表');
        });

        Schema::create('channels', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 10)
                ->comment('名称');
            $table->datetimes();
            $table->comment('渠道表');
        });

        Schema::create('staffs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 10)
                ->comment('名称');
            $table->string('password', 100)
                ->comment('密码');
            $table->char('phone', 11)
                ->comment('手机号');
            $table->string('avatar', 255)
                ->comment('头像');
            $table->datetimes();
            $table->comment('员工表');
        });

        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('member_id')
                ->index('member_id')
                ->comment('用户ID');
            $table->unsignedBigInteger('car_id')
                ->index('car_id')
                ->comment('车辆ID');
            $table->unsignedBigInteger('channel_id')
                ->index('channel_id')
                ->default(0)
                ->comment('渠道ID');
            $table->unsignedBigInteger('staff_id')
                ->index('staff_id')
                ->default(0)
                ->comment('员工ID');
            $table->unsignedBigInteger('no')
                ->comment('订单号');
            $table->string('city', 10)
                ->comment('城市');
            $table->string('address', 50)
                ->comment('地址');
            $table->datetime('start_at')
                ->comment('开始时间');
            $table->datetime('end_at')
                ->comment('结束时间');
            $table->unsignedSmallInteger('day')
                ->comment('租车天数');
            $table->unsignedSmallInteger('price')
                ->comment('租车单价');
            $table->unsignedSmallInteger('cleaning_fee')
                ->comment('清洁费');
            $table->unsignedSmallInteger('service_fee')
                ->comment('服务费');
            $table->unsignedSmallInteger('insurance_price')
                ->comment('保险单价');
            $table->unsignedSmallInteger('total_price')
                ->comment('总价格');
            $table->string('pay_no', 50)
                ->default('')
                ->comment('支付单号');
            $table->dateTime('pay_launch_at')
                ->nullable()
                ->comment('支付发起时间');
            $table->dateTime('pay_confirm_at')
                ->nullable()
                ->comment('支付确认时间');
            $table->dateTime('pay_lapse_at')
                ->comment('支付失效时间');
            $table->unsignedTinyInteger('pay_status')
                ->default(0)
                ->comment('支付状态:0=未支付,1=支付中,2=付款成功,3=付款失败');
            $table->unsignedTinyInteger('is_delivery')
                ->default(0)
                ->comment('是否送达:0=否,1=是');
            $table->dateTime('delivery_at')
                ->nullable()
                ->comment('送达时间');
            $table->dateTime('cancelled_at')
                ->nullable()
                ->comment('取消时间');
            $table->dateTime('return_at')
                ->nullable()
                ->comment('还车时间');
            $table->unsignedTinyInteger('status')
                ->default(0)
                ->comment('状态:0=待支付,1=进行中,2=已完成,3=已取消,4=已失效');
            $table->datetimes();
            $table->comment('订单表');
        });

        Schema::create('order_cars', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('order_id')
                ->index('order_id')
                ->comment('订单ID');
            $table->unsignedBigInteger('car_id')
                ->index('car_id')
                ->comment('车辆ID');
            $table->json('car_category_ids')
                ->comment('车辆分类ID');
            $table->json('banner')
                ->comment('轮播图');
            $table->string('cover', 255)
                ->comment('封面图');
            $table->string('name', 10)
                ->comment('名称');
            $table->unsignedSmallInteger('price')
                ->comment('单价(天)');
            $table->string('describe', 32)
                ->comment('描述');
            $table->json('base_config')
                ->comment('基础配置');
            $table->json('high_light_config')
                ->comment('突出配置');
            $table->datetimes();
            $table->comment('订单快照车辆表');
        });

        Schema::create('order_lessees', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('order_id')
                ->index('order_id')
                ->comment('订单ID');
            $table->unsignedBigInteger('lessee_id')
                ->index('lessee_id')
                ->comment('承租人ID');
            $table->unsignedBigInteger('member_id')
                ->index('member_id')
                ->comment('用户ID');
            $table->string('name', 10)
                ->comment('姓名');
            $table->char('phone', 11)
                ->comment('手机号');
            $table->char('id_card', 18)
                ->comment('身份证号');
            $table->unsignedTinyInteger('is_default')
                ->default(0)
                ->comment('是否默认:0=否,1=是');
            $table->datetimes();
            $table->comment('订单快照承租人表');
        });

        Schema::create('order_insurances', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('order_id')
                ->index('order_id')
                ->comment('订单ID');
            $table->unsignedBigInteger('insurance_id')
                ->index('insurance_id')
                ->comment('保险ID');
            $table->unsignedTinyInteger('level')
                ->comment('保险等级');
            $table->string('name', 10)
                ->comment('名称');
            $table->string('car_damage', 10)
                ->comment('车损保障');
            $table->string('car_damage_sub', 10)
                ->comment('车损保障副描述');
            $table->string('tripartite', 10)
                ->comment('三者保障');
            $table->string('passenger', 10)
                ->comment('乘客保障');
            $table->unsignedTinyInteger('free_depreciation')
                ->comment('免折旧费:0=否,1=是');
            $table->unsignedTinyInteger('no_need_advance')
                ->comment('无需垫付:0=否,1=是');
            $table->unsignedTinyInteger('free_outage')
                ->comment('免停运费:0=否,1=是');
            $table->unsignedSmallInteger('original_price')
                ->comment('原本单价(天)');
            $table->unsignedSmallInteger('price')
                ->comment('单价(天)');
            $table->text('detail')
                ->comment('详情');
            $table->datetimes();
            $table->comment('订单快照保险表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('members');
        Schema::dropIfExists('lessees');
        Schema::dropIfExists('car_categories');
        Schema::dropIfExists('cars');
        Schema::dropIfExists('insurances');
        Schema::dropIfExists('channels');
        Schema::dropIfExists('staffs');
        Schema::dropIfExists('orders');
        Schema::dropIfExists('order_cars');
        Schema::dropIfExists('order_lessees');
        Schema::dropIfExists('order_insurances');
    }
}
